package the.world.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import the.world.bean.Game;
import the.world.bean.HotArticles;
import the.world.bean.Navigation;
import the.world.service.impl.GuiServiceImpl;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class GuideController {
    @Autowired
    private GuiServiceImpl guiService;
    @GetMapping("/guide/{name}")
    public ModelAndView responseList(@PathVariable("name") String name) {
        ModelAndView modelAndView = new ModelAndView();
        List<Game> list = guiService.responseTitleData(name);
        List<HotArticles> hotArticles = guiService.findByGameName(name);
        List<Navigation> navigationPath = guiService.getNavigationPath("guide");
        if (!list.isEmpty() && !hotArticles.isEmpty()) {
            modelAndView.addObject("gameList", list);
            modelAndView.addObject("topPost", hotArticles);
            modelAndView.addObject("navigationPath", navigationPath);
            modelAndView.addObject("whereName", name);
            modelAndView.setViewName("guide");
        } else {
            modelAndView.setViewName("error");
        }
        return modelAndView;
    }
}
